package jianzhi_offer;

public class _29_连续子数组的最大和 {
    public static void main(String[] args) {
        _29_连续子数组的最大和 test = new _29_连续子数组的最大和();
        System.out.println(test.FindGreatestSumOfSubArray(new int[]{-2,-8,-1,-5,-9}));
    }
    public int FindGreatestSumOfSubArray(int[] array) {
        int max= Integer.MIN_VALUE, con = max;
        for(int i:array){
            if(con < 0){
                con = i;
            }else{
                con += i;
            }
            max = Math.max(max,con);
        }
        return max;
    }
}
